package Day2025_03_03;

import java.util.Stack;

public class HomeWork06 {
    public double operation (String str) {
        char[] nums = str.toCharArray();
        int n = nums.length;
        Stack<Character> stack1 = new Stack<>();
        Stack<Double> stack2 = new Stack<>();
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == '+' || nums[i] == '-' || nums[i] == '*' || nums[i] == '/') stack1.push(nums[i]);
            if (nums[n - 1 - i] > '0' && nums[n - 1 - i] < '9') stack2.push((double) nums[n - 1 - i] - '0');
        }
        while (!stack1.isEmpty()) {
            double a = stack2.pop();
            double b = stack2.pop();
            char op = stack1.pop();
            switch (op) {
                case '+':
                    stack2.push(a + b);
                    break;
                case '-':
                    stack2.push(a - b);
                    break;
                case '*':
                    stack2.push(a * b);
                    break;
                case '/':
                    stack2.push(a / b);
                    break;
            }
        }
        return stack2.pop();
    }

    public static void main(String[] args) {
        HomeWork06 homeWork06 = new HomeWork06();
        System.out.println(homeWork06.operation("/+345"));
    }
}